package com.tiancheng.trade.payment.channel.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 银联商务订单支付状态
 */
@Getter
@AllArgsConstructor
public enum UmsOrderStatusEnum {
    NEW_ORDER("NEW_ORDER", "新订单"),
    UNKNOWN("UNKNOWN", "不明确的交易状态"),
    TRADE_CLOSED("TRADE_CLOSED", "在指定时间段内未支付时关闭的交易；在交易完成撤销成功时关闭的交易；支付失败的交易(TRADE_CLOSED的交易不允许进行任何操作)"),
    WAIT_BUYER_PAY ("WAIT_BUYER_PAY", "交易创建，等待买家付款"),
    TRADE_SUCCESS("TRADE_SUCCESS", "支付成功"),
    TRADE_REFUND("TRADE_REFUND", "订单转入退货流程(退货可能是部分也可能是全部)"),
    ;
    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<UmsOrderStatusEnum> mOrderStatusEnum = Arrays.stream(UmsOrderStatusEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (mOrderStatusEnum.isPresent()) {
            return mOrderStatusEnum.get().getDesc();
        }
        return "";
    }

    public static UmsOrderStatusEnum getByCode(String code) {
        for (UmsOrderStatusEnum orderStatusEnum : values()) {
            if (orderStatusEnum.getCode().equals(code)) {
                return orderStatusEnum;
            }
        }
        return UNKNOWN;
    }
}
